package com.ldq.imooc.basics.socket;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;

/**
 * @Author : 李道泉
 * @Description :InetAddress 类
 * @Date : 2018/4/23 13:35
 * @Modified by :
 */
public class NetTest {

    public static void main(String[] args) throws UnknownHostException {

        //获取InetAddress类实例
        InetAddress address = InetAddress.getLocalHost();
        System.out.println("计算机名：" + address.getHostName());
        System.out.println("IP地址：" + address.getHostAddress());

        byte[] bytes = address.getAddress();
        System.out.println("字节数组形式IP地址：" + Arrays.toString(bytes));

        System.out.println(address);

        //根据机器名获取InetAddress实例
        InetAddress address1 = InetAddress.getByName("DESKTOP-M5AGBA0");
        System.out.println("计算机名：" + address1.getHostName());
        System.out.println("IP地址：" + address1.getHostAddress());
    }
}
